﻿// See https://aka.ms/new-console-template for more information
namespace ConsoleAppDownLoadFileDemo
{
    public class Program
    {
        static async Task Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            var result = false;
            int num = 0;
            do
            {
                result = await DownLoadFileAsync();
                if(!result)
                {
                    num++;
                    Console.WriteLine($"Download failed, try {num} times");
                }
            }
            while (!result && num <= 3);         
        }

        private async static Task<bool> DownLoadFileAsync()
        {
            try
            {
                using var httpClient = new HttpClient();
                var response =await httpClient.GetAsync("https://www.baid32u.com");
                return true;
            }
            catch (HttpRequestException e)
            {
                return false;
            }
            catch (Exception e)
            {
                throw;
            }
        }
    }
}

